//
//  TwoColumnView.swift
//  TanTan_Kotlin
//
//  Created by EDY on 5/23/25.
//

import SwiftUI

struct TwoColumnView<Content : View> : View {

    
    
    let leftTitle: String
    let leftContent: Content
    let rightTitle: String
    let rightContent: Content
    
    init(leftTitle: String,@ViewBuilder leftContent: () -> Content, rightTitle: String, @ViewBuilder rightContent: () -> Content) {
        self.leftTitle = leftTitle
        self.leftContent = leftContent()
        self.rightTitle = rightTitle
        self.rightContent = rightContent()
    }
    
    var body: some View {
        HStack {
            VStack(alignment: .leading){
                Text(leftTitle)
                    .font(.headline)
                    leftContent
            }
            .padding()
            .background(.gray)
            Spacer()
            VStack(alignment: .leading){
                Text(rightTitle)
                    .font(.headline)
                rightContent
            }
            .padding()
            .background(.yellow)
        }
    }
    
}

#Preview {
    TwoColumnView(leftTitle: "左列标题", leftContent: {
        Text("左列项目 1")
        Text("左列项目 2")
    }, rightTitle: "右列标题") {
        Text("右列项目 1")
        Text("右列项目 2")
    }
}
